<?php
header('Content-Type: application/json');

// 获取WebSocket服务器配置
$configFile = dirname(__DIR__) . '/websocket_config.json';

if (file_exists($configFile)) {
    $config = json_decode(file_get_contents($configFile), true);
    
    if ($config) {
        echo json_encode([
            'success' => true,
            'host' => $config['host'] ?? 'localhost',
            'port' => $config['port'] ?? 8080,
            'updated_at' => $config['updated_at'] ?? null
        ]);
    } else {
        echo json_encode([
            'success' => false,
            'message' => '配置文件格式错误',
            'host' => 'localhost',
            'port' => 8080
        ]);
    }
} else {
    // 如果配置文件不存在，返回默认配置
    echo json_encode([
        'success' => false,
        'message' => 'WebSocket服务器未启动',
        'host' => 'localhost',
        'port' => 8080
    ]);
}
?>
